home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 301-325 / disk_313 / uucp / uucp1.lzh / src / uucico / modem.c < prev    next >
C/C++ Source or Header  |  1990-01-10  |  3KB  |  190 lines

  1.  
  2. /*
  3.  *  MODEM.C
  4.  *
  5.  *  (C) Copyright 1989-1990 by Matthew Dillon,  All Rights Reserved.
  6.  *
  7.  */
  8.  
  9. #include "includes.h"
  10. #include "uucp.h"
  11. #include "sysdep.h"
  12. #include "modem.h"
  13. #include "log.h"
  14.  
  15. /*
  16.  *  NOTE:   modem stuff pretty much ignored if we are run from
  17.  *        a getty.
  18.  */
  19.  
  20. #define MULTIMODEM    /*  I have a multi-modem    */
  21.  
  22. extern int Getty;
  23. extern int IgnoreCD;
  24.  
  25. int twrite();
  26. int instr();
  27.  
  28. void set_baud();
  29.  
  30. void
  31. openline()
  32. {
  33.     signal(SIGINT,sigint);
  34.     IgnoreCD |= 4;
  35. start_again:
  36.     chkabort();
  37.     if (instr("CONNECT", 7))
  38.     goto start_again;
  39.  
  40.  
  41. #ifdef MULTIMODEM
  42.  
  43. #else
  44.     set_baud(get_baud());
  45. #endif
  46.     Delay(120); /* sleep 2 seconds */
  47.  
  48.     IgnoreCD &= ~4;
  49. }
  50.  
  51. #ifndef MULTIMODEM
  52.  
  53. int
  54. get_baud()
  55. {
  56. /* We've seen the CONNECT message, now we must see what baud rate
  57.    we've connected with */
  58. /* gather input until \r then see if it's 300, 1200, or 2400 */
  59. /* this is for hayes compatibles */
  60.  
  61.     int data;
  62.     char rate[10];
  63.     int rate_inx = 0;
  64.  
  65.     DEBUG(2,"looking for baud rate\n",0);
  66.  
  67.     while ( ((data = xgetc(BYTE_TO)) != EOF) && ((char)data != '\r')) {
  68.         if ((char)data == ' ') continue;
  69.         rate[rate_inx++] = (char)data;
  70.     }
  71.     DEBUG(2, "found baud rate of %s\n", rate);
  72.     if (strncmp(rate,"1200",4) == 0) return 1200;
  73.     if (strncmp(rate,"2400",4) == 0) return 2400;
  74.     if (rate_inx == 0) return 300;
  75.     return 1200;  /* default */
  76. }
  77.  
  78. #endif
  79.  
  80. void
  81. modem_init()
  82. {
  83.     reset_modem();
  84. }
  85.  
  86. /*
  87.  * Simple dialer routine.  Needs replacement with a full blown
  88.  * script driven dialer.  Next week maybe :-).    FIXME.
  89.  */
  90.  
  91. int
  92. dial_nbr(nbr)
  93. char  *nbr;
  94. {
  95.     char  dial[30];
  96.     int   i;
  97.  
  98.     IgnoreCD |= 4;
  99.  
  100.     sprintf(dial, "%s%s\r", "ATDT", nbr);
  101.  
  102.     DEBUG(2,"dialing %s\n", dial);
  103.  
  104.     twrite(dial, strlen(dial));
  105.  
  106.     i = instr("CONNECT", 7);
  107.  
  108.     if (i == 0)     /*  for those modems which don't bring CD up */
  109.     Delay(50);  /*  immediately                              */
  110.  
  111.     IgnoreCD &= ~4;
  112.  
  113.     return (i);
  114. }
  115.  
  116. /*
  117.  *  RESET_MODEM()
  118.  *
  119.  *  If run from a Getty we do NOT reset the modem, which would
  120.  *  disconnect an already connected connection.
  121.  *
  122.  *  Note that the delay between CloseSerial() and OpenSerial() only
  123.  *  serves to give the Getty, if running, time to lock the port and
  124.  *  begin a disconnect sequence.
  125.  */
  126.  
  127. void
  128. reset_modem()
  129. {
  130.     if (Getty)          /*  called from a getty             */
  131.     return;
  132.     DEBUG(4, "Beg-Reset\n", 0);
  133.     CloseSerial();      /*  drop dtr            */
  134.     Delay(50*3);        /*  delay 3 seconds     */
  135.     DEBUG(4, "End-Reset-1\n", 0);
  136.     OpenSerial();       /*  re-open serial      */
  137.     DEBUG(4, "End-Reset-2\n", 0);
  138. }
  139.  
  140. #ifdef NOTDEF
  141.  
  142.     if (GettyCmd(DeviceName, DeviceUnit, '0', NULL) == 0)
  143.     return;
  144.  
  145.     /*
  146.      *    Getty doesn't exist, we have to reset the modem ourselves!
  147.      */
  148.  
  149.     IgnoreCD |= 4;
  150.  
  151. #ifdef MULTIMODEM
  152.     set_baud(19200);
  153.  
  154.     if (CheckCarrier()) {
  155.     Delay(60);
  156.     twrite("+++", 3);
  157.     Delay(120);
  158.     }
  159.     twrite("ATH0\r", 5);
  160.     instr("OK\r\n", 4);
  161.     twrite("ATZ\r", 4);
  162.     instr("OK\r\n", 4);
  163.     twrite("ATZ\r", 4);
  164.     instr("OK\r\n", 4);
  165.  
  166.     /*amiga_closeopen();*/
  167.     sprintf(init, "%s\r", "ATM0S0=2X4$BA0");
  168.     if (debug > 0)
  169.     init[3] = '1';
  170.     twrite(init, strlen(init));
  171.     instr("OK\r\n",4);
  172. #else
  173.     twrite("+++", 3);
  174.     Delay(60);
  175.     twrite("ATH0\r", 5);
  176.     Delay(120);
  177.     twrite("ATZ\r", 4);
  178.     Delay(60);
  179.     twrite("ATZ\r", 4);
  180.     Delay(60);
  181.     sprintf(init, "%s\r", "ATS2");
  182.     twrite(init, strlen(init));
  183.     Delay(60);
  184. #endif
  185.     IgnoreCD &= ~4;
  186. }
  187.  
  188. #endif
  189.  
  190.